import Phaser from 'phaser'
import PlayerBase from "./PlayerBase";
import Director from './Director';

/**
 * Tiequan
 */
export default class PlayerTiequan extends PlayerBase {
    constructor(director: Director) {
        super(director, "sanim_234051");
    }

    /** 动作帧事件 */
    protected actionEvent(action: string, actionEventName: string) {
        /** 必杀技 */
        if (action == 'ultimateskill') {
            if (actionEventName != 'back') {
                // this.ultimateskill(actionEventName);
            }
        }
        /** 技能 */
        else if (action == 'skill') {
            if (actionEventName != 'back') {
                // this.skill(actionEventName);
            }
        }
        else if (action == 'att') {
            if (actionEventName != 'back') {
                // this.attack(actionEventName);
            }
        }

    }

    /* 普通攻击 */
    private attack(eventName: string): void {
        if (eventName == 'faqi_1') {
            let attachedLeft = -100;
            let attachedTop = -70;
            let attachedRight = 0;
            let attachedBottom = -150;
            let backValue = 20;

            if (this.directionX == 'left') {
                attachedLeft = 100;
                backValue = 0 - backValue;
            }

            let scope: number[] = this.attackScope(attachedLeft, attachedTop, attachedRight, attachedBottom, true);
            let players: PlayerBase[] = this.director.findAttachedPlayers(this, scope[0], scope[1], scope[2], scope[3]);
            console.log(backValue)
            players.forEach((player) => {

                player.beHit(this.physicsHurt, 0, backValue, 0);
            });
        }

    }

    /** 技能 */
    private skill(eventName: string): void {
        // console.log(eventName);
        let backValue = 100;
        let attachedTop = -40;
        let attachedRight = 5;
        let attachedLeft = -160;
        let attachedBottom = -120;
        if (this.directionX == 'left') {
            backValue = 0 - backValue;
        }

        if (eventName == 'chufa_11_3_3') {
            if (this.directionX == 'left') {
                attachedLeft = 160;
            }

            let scope: number[] = this.attackScope(attachedLeft, attachedTop, attachedRight, attachedBottom, true);
            let players: PlayerBase[] = this.director.findAttachedPlayers(this, scope[0], scope[1], scope[2], scope[3]);
            players.forEach((player) => {
                player.beHit(this.skillOne.physicsHurt, 0, backValue);
            });
        }
        if (eventName == 'chufa_11_3_2') {
            attachedRight = 5 + 100;
            if (this.directionX == 'left') {
                attachedLeft = 160 + 100;
            }
            let scope: number[] = this.attackScope(attachedLeft, attachedTop, attachedRight, attachedBottom, true);
            let players: PlayerBase[] = this.director.findAttachedPlayers(this, scope[0], scope[1], scope[2], scope[3]);
            players.forEach((player) => {
                player.beHit(this.skillOne.physicsHurt, 0, backValue);
            });
        }
        if (eventName == 'chufa_11_3_1') {
            attachedRight = 5 + 100 + 80;
            if (this.directionX == 'left') {
                attachedLeft = 160 + 100 + 80;
            }
            let scope: number[] = this.attackScope(attachedLeft, attachedTop, attachedRight, attachedBottom, true);
            let players: PlayerBase[] = this.director.findAttachedPlayers(this, scope[0], scope[1], scope[2], scope[3]);
            players.forEach((player) => {
                player.beHit(this.skillOne.physicsHurt, 0, backValue);
            });
        }

    }


    /* 必杀技*/
    private ultimateskill(eventName: string): void {
        if (eventName == 'faqi_21') {

            let attachedLeft = 220;
            let attachedRight = 465;
            let attachedTop = 15;
            let attachedBottom = 40;

            if (this.directionX == 'left') {
                attachedLeft = 245;
                attachedRight = 465;
            }
            let scope: number[] = this.attackScope(attachedLeft, attachedTop, attachedRight, attachedBottom, true);

            let players: PlayerBase[] = this.director.findAttachedPlayers(this, scope[0], scope[1], scope[2], scope[3]);
            players.forEach((player) => {
                /** 先简单固伤策略 物理攻击 + 技能伤害 */
                player.beHit(0, this.skillTwo.magicHurt, 0, 3);
            });
        }
    }
}